package com.woniuxy.consumerfeign.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.woniuxy.commons.entity.Goods;
import com.woniuxy.commons.service.ProviderService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author zhangyong
 * @Date 2021/8/3 0003
 */
@RestController
@RequestMapping("/feign")
public class FeignController {
    @Resource
    private ProviderService providerService;

    @HystrixCommand
    @GetMapping("/all")
    public List<Goods> all(){
        //请求provider得到数据:通过oenfeign
        return providerService.all();
    }

    //find
    @GetMapping("/find")
    public Goods findById(){
        return providerService.findById(2001);
    }

    //add
    @GetMapping("/add")
    public void add(){
        Goods goods = new Goods(2002,"香蕉",10000);
        providerService.add(goods);
    }

    //update
    @PutMapping("/update")
    public Boolean update(){
        Goods goods = new Goods(2002,"菠萝",399);
        providerService.update(goods);
        return true;
    }

    //del
    @DeleteMapping("/del")
    public void del(){
        providerService.del(2002);
    }
}
